<?php
namespace Home\Controller;
use Think\Controller;

/*
get_img($json) 将图片中的json格式，转成正常数组
get_tpl($id, $type)  跟据栏目id，获取对应模板
get_channel_list()   获取当前栏目下的数据
danye($id)            获取专题数据
htmlspecialchars_decode()  html实体转成html标签
channel()                  获取栏目导航
page($type);   $type=prev|next  上一页|下一页
get_doc($navid,$limit)   $navid栏目id   $limit  输出条数  获取指定栏目中的数据
 */
class IndexController extends Controller {
	public function _initialize() {
		if (ismobile()) {

			$url = U('Mobile/Index/index');
			header("location:{$url}");
		}
	}
	public function index() {

		$_GET['mid'] = 41;
		$_GET['id'] = 15;
		//推荐产品
		$map[' shuxing'] = '推荐';
		$this->list = get_channel_list($map);
		//留言模板
		$this->messages();
		//最新留言
		$this->NewMessage();
		$this->display();

	}
	//最新留言
	private function NewMessage() {
		$this->newsmessage = M(GetModelTable(47))->limit(10)->order('id desc')->cache(true, 10)->select();
	}
	private function messages() {
		//留言
		$number = 47;
		$ControllerName = D('Admin/Model');
		$html = $ControllerName->FormLayout($number);
		$this->assign('mid', $number);
		$this->assign('form', $html);
		$this->assign('actionurl', U('addMassage', array('mid' => $number)));
	}
	//添置留言
	public function addMassage() {
		$ControllerName = D('Admin/Model');
		$number = I('get.mid', '', 'intval');
		//模型条件数据
		if (IS_POST) {
			$data = $ControllerName->ModelDataJson($number);

			if ($data['status']) {
				sendEmail('573725206@qq.com', '有人咨询洗车机了', '你自己看看邮件呀' . I('post.shouji'));
				$this->success($data['info'], $url);
			} else {
				$this->error($data['info']);
			}

		}
	}

	//关于我们
	public function about() {
		$this->display('tel');
	}
	//联系我们
	public function contact() {
		//留言模板
		$this->messages();
		$this->danye = danye(intval(2));
		$this->display('about');
	}
	//产品单独显示中心
	public function ShopMain() {
		for ($i = 2; $i < 86; $i++) {
			$n[] = "http://img.qcwu.com.cn/xicheji/news/" . $i . '.jpg!min';
		}
		$this->list = $n;
		$this->display();
	}
	//配件单独显示
	public function Parts() {
		$this->display();
	}
	//合作加盟
	public function join() {
		$this->location = file_get_contents("http://weixin.qcwu.com.cn/app/index.php?i=2&c=entry&m=zhouzheng_wash&do=Location");
		$this->danye = danye(intval(3));
		$this->display();
	}
	//产品中心
	public function Shop() {
		$id = I('get.id', '', 'intval');
		if (!$id) {return false;}
		$navs = cache_table(GetModelTable(41), array('id' => $id));
		$this->title = $navs['0']['lanmumingcheng']; //栏目标题
		//栏目分类查询条件
		$this->list = get_channel_list(array('browse' => $id));
		//栏目对应模板
		$this->display(get_tpl($id, 'list'));
	}
	//技术中心
	public function jishu() {
		$this->Shop();
	}
	//内容页
	public function doc() {
		//所属文章id
		$id = I('get.id', '', 'intval');
		//所属栏目id
		$t = I('get.t', '', 'intval');
		if (!$t) {return false;}
		if (!$id) {return false;}
		//找出所属模板，及所属内容模型
		$tpl = cache_table(GetModelTable(41), array('id' => $t));
		//内容数据
		$map['id'] = $id;
		$this->data = M(GetModelTable($tpl['0']['suoshumoxing']))->where($map)->cache(true, 60 * 24)->field(true)->find();
		//使用自定义模板
		$this->display(get_tpl(I('get.t'), 'doc'));
	}
	/*
		  *生成手机二维码
	*/
	public function code($url) {
		$url = str_replace('-', '/', I('get.url'));
		D('Admin/User')->code($url);
	}
	//微信支付回调
	public function notify() {
		$time = time();
		$id = I('get.id');
		$money = I('get.money');
		$end = $time + (60 * $money);
		// echo date('Y-m-d H:i:s', $time);
		// echo date('Y-m-d H:i:s', $end);
		$data['code'] = $id;
		$data['money'] = $money;
		$data['pay_type'] = 'weixinpay';
		$data['open_time'] = $time; //开始时间
		$data['end_time'] = $end; //结束时间
		$type = M('pay')->add($data);
		if ($type) {
			echo 'success';
		} else {
			echo 'error';
		}
	}
}